<?php

use yii\helpers\Html;
use common\entities\cms\DirEntity;
?>
<div ng-view="" class="ng-scope">
    <div data-ng-controller="contractDredgeCtrl" class="ng-scope">
        <div class="table-header clearfix ng-scope">
            <span class="fl lh30 f14 ng-binding">媒体编辑</span>
        </div>
        <?php if ($model->hasErrors()) echo Html::errorSummary($model, ['class' => 'errorSummary']); ?>
        <?php echo Html::beginForm($model->getIsNewRecord() ? [''] : ['', 'id' => $model->getPrimaryKey()], 'post', ['enctype' => 'multipart/form-data', 'autocomplete' => 'off', 'class' => 'form-horizontal ng-pristine ng-valid']); ?>
        <div class="form-group mt10">
            <span class="col-sm-3 control-label ml15">
                <?php echo Html::activeLabel($model, 'dir_id'); ?>
            </span>
            <div class="col-sm-5">
                <?php echo Html::activeDropDownList($model, 'dir_id', DirEntity::getOptions('media'), ['class' => 'form-control']); ?>
            </div>
        </div>

        <div class="form-group mt10">
            <span class="col-sm-3 control-label ml15">
                <?php echo Html::activeLabel($model, 'name'); ?>
            </span>
            <div class="col-sm-18">
                <?php echo Html::activeTextInput($model, 'name', ['class' => 'form-control']); ?>
            </div>
        </div>
        <div class="form-group mt10">
            <span class="col-sm-3 control-label ml15">
                <?php echo Html::activeLabel($model, 'status'); ?>
            </span>
            <div class="col-sm-2">
                <?php echo Html::activeCheckbox($model, 'status', ['label' => '']); ?>
            </div>
        </div>
        <div class="form-group mt10">
            <span class="col-sm-3 control-label ml15">
                填写资源地址
            </span>
            <div class="col-sm-18">
                <?php echo Html::activeTextInput($model, 'file', ['class' => 'form-control']); ?>
            </div>
        </div>
        <div class="form-group mt10">
            <span class="col-sm-3 control-label ml15">
                <?php echo Html::activeLabel($model, 'file'); ?>
            </span>
            <div class="col-sm-18">
                <?php if (empty($model->file)): ?>
                    <?php echo Html::activeFileInput($model, 'resourcesFile',['onchange' => 'fileChange(this)']); ?>
                <?php endif; ?>
                <?php if ($model->file) : ?>
                    <?php echo Html::a($model->file, $model->file, array('target' => '_blank')); ?>
                    <div style="width:295px;" id="videoplay">
                        <?php if (in_array($model->type, ['jpg', 'gif', 'png', 'jpeg'])) echo Html::a(Html::img($model->file, ['alt' => $model->image_info]), $model->file, array('target' => '_blank')); ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>

        <div class="form-group">
            <div class="ml35 mt15">
                <?php echo Html::submitButton('保存', ['class' => 'btn btn-default ng-scope', 'id' => 'submit']); ?>
                <?php echo Html::a('返回列表', '?r=/cms/media/index', ['class' => 'btn btn-yellow']); ?>
            </div>
        </div>
        <?php echo Html::endForm(); ?>
    </div>
</div>

<script type="text/javascript"> 
  var isIE = /msie/i.test(navigator.userAgent) && !window.opera;       
  function fileChange(target) {   
    
    var fileSize = 0;        
    if (isIE && !target.files) {    
      var filePath = target.value;    
      var fileSystem = new ActiveXObject("Scripting.FileSystemObject");       
      var file = fileSystem.GetFile (filePath);    
      fileSize = file.Size;   
    } else {   
     fileSize = target.files[0].size;    
     }  
     var size = fileSize / 1024;   
     if(size>8000){ 
      alert("附件不能大于8M"); 
      $('#submit').attr('disabled', true);
     } else {
      $('#submit').attr('disabled', false);
     }
}  
</script> 

